package genericity;

import java.util.Objects;

public class test1 {
    public static void main(String[] args) {
        /*int N = 9;
        int count = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                count++;
            }
        }
        for (int k = 0; k < 2 * N; k++) {
            count++;
        }
        int M = 10;
        while ((M--) > 0) {
            count++;
        }
        System.out.println(count);
    }

    void bubbleSort(int[] array) {
        for (int end = array.length; end > 0; end--) {
            boolean sorted = true;
            for (int i = 1; i < end; i++) {
                if (array[i - 1] > array[i]) {
                    Swap(array, i - 1, i);
                    sorted = false;
                }
            }
            if (sorted == true) {
                break;
            }
        }
    }
}

    int binarySearch(int[] array, int value) {
        int begin = 0;
        int end = array.length - 1;
        while (begin <= end) {
            int mid = begin + ((end-begin) / 2);
            if (array[mid] < value)
                begin = mid + 1;
            else if (array[mid] > value)
                end = mid - 1;
            else
                return mid;
        }
        return -1;
    }*/
        //装箱
       /* Array array=new Array();
        array.set(0,"string");
        array.set(1,1);
        Object ret=array.get(0);
        Object ret1=array.get(1);
        System.out.println(ret);
        System.out.println(ret1);
*/
      /*  Array<Integer> array=new Array<>();
        array.set(1,1);
        int ret= array.get(1);
        System.out.println(ret);*/
/*class Array{
    Object o[]=new Object[10];
    public void set(int index,Object data){
        o[index]=data;
    }
    public Object get(int index){
        return o[index];
    }
}*/

/*
class Array<T>{
    Object[] o=new Object[10];
    public void set(int index,T data){
        o[index]=data;
    }
    public T get(int index){
        return (T) o[index];
    }
}
*
 */
        Array<String> array = new Array<>();
        String arr[] = {"hello","world"};
        String a = array.findMax(arr);
        System.out.println(a);


        Array1 array1=new Array1();
        String arr1[]={"hello","world"};
        String ret=array1.<String>findMax(arr);
        System.out.println(ret);

    }

}

class Array<T extends Comparable<T>> {
    public T findMax(T[] array){
        T max=array[0];
        for (int i = 0; i <array.length ; i++) {
            if(array[i].compareTo(max)>0){
                max=array[i];
            }
        }
        return max;
    }
}
class Array1{
    public <T extends Comparable<T>>  T findMax(T[] array){
        T max=array[0];
        for (int i = 0; i <array.length ; i++) {
            if(array[i].compareTo(max)>0){
                max=array[i];
            }
        }
        return max;


    }
}
